#!coding=utf-8
from django.db import models
import settings
import datetime
from enterprise_basic_information.models import *
from map_data.models import *

#表二
#设计危险化学品生产线基本信息
# class Production_line_basic(models.Model):
#     serial_number = models.CharField(u'生产线编号',max_length = 30)
#     name = models.CharField(u'生产线名称',max_length = 30)
#     production_name = models.CharField(u'产品名称',max_length = 30)
#     raw_materials_name = models.CharField(u'原辅料名称',max_length = 30)
#     process_name = models.CharField(u'工艺方法名称',max_length = 200)
#     chemical_name = models.CharField(u'特征化学污染物名称',max_length = 200)

# 生产区
class ProductArea(models.Model):
    name = models.CharField(u'生产区名称', max_length=50)
    desc = models.CharField(u'生产区描述', max_length=200)
    mapdata = models.ForeignKey(MapData, null=True)
    app_status = models.ForeignKey(Application_status, null=True)
    submit_type = models.IntegerField(u'确认状态', max_length=13)
    enterprise = models.ForeignKey(Enterprise)

    def getObj(self):
        _dict = {}
        _dict['id'] = self.id
        _dict['name'] = self.name
        _dict['desc'] = self.desc
        return _dict

    def clone(self):
        if self.id :
            self.id = None
            self.status = '1'
            self.submit_time = ''
            return self
        else:
            return u'数据未入库'

# 生产单元
class Production(models.Model):
    name = models.CharField(u'名称', max_length=50)
    count = models.CharField(u'数量', max_length=50)
    in_unit = models.CharField(u'所在单位', max_length=50)
    code = models.CharField(u'生产编号', max_length=50)
    risk = models.CharField(u'风险特征', max_length=50)
    design_year = models.CharField(u'设计年限', max_length=50)
    use_year = models.CharField(u'使用年限', max_length=50)
    is_check = models.CharField(u'是否通过检查', max_length=50)
    error_rate = models.CharField(u'故障率', max_length=50)
    repair_rate = models.CharField(u'维修频率', max_length=50)
    is_monit = models.CharField(u'是否监控', max_length=50)
    add_time = models.DateTimeField(u'添加时间', default=datetime.datetime.now())
    product_area = models.ForeignKey(ProductArea)

    def getObj(self):
        _dict = {}
        _dict['id'] = self.id
        _dict['name'] = self.name
        _dict['code'] = self.code
        return _dict

    def changeProductArea(self,pa):
        if self.id:
            self.id = None
            self.product_area = pa
            return self
        else:
            return u'数据为入库'

class StorageArea(models.Model):
    name = models.CharField(u'生产区名称', max_length=50)
    desc = models.CharField(u'生产区描述', max_length=200)
    mapdata = models.ForeignKey(MapData, null=True)
    app_status = models.ForeignKey(Application_status, null=True)
    submit_type = models.IntegerField(u'确认状态', max_length=13)
    enterprise = models.ForeignKey(Enterprise)

    def getObj(self):
        _dict = {}
        _dict['id'] = self.id
        _dict['name'] = self.name
        _dict['desc'] = self.desc
        return _dict


# 贮罐区
class StorageTank(models.Model):
    name = models.CharField(u'名称', max_length=50)
    to_product = models.CharField(u'对应产品', max_length=50)
    mode = models.CharField(u'储罐形式', max_length=50)
    nitrogen_sealed = models.CharField(u'氮气密封', max_length=50)
    para = models.CharField(u'规格参数', max_length=50)
    count = models.CharField(u'储罐数量', max_length=50)
    error_rate = models.CharField(u'故障率', max_length=50)
    repair_rate = models.CharField(u'维修频率', max_length=50)
    is_monit = models.CharField(u'是否监控', max_length=50)
    add_time = models.DateTimeField(u'添加时间', default=datetime.datetime.now())
    storage_area = models.ForeignKey(StorageArea)
    
    def getObj(self):
        _dict = {}
        _dict['id'] = self.id
        _dict['name'] = self.name
        _dict['mode'] = self.mode
        return _dict

#表三
#涉及危险化学品生产线信息
class Production_line_information(models.Model):
    serial_number = models.CharField(u'生产线编号',max_length = 30)
    name = models.CharField(u'生产线名称',max_length = 30)

    #production
    production_name = models.CharField(u'产品名称',max_length = 30)
    production_classification = models.CharField(u'产品分类代码',max_length = 30)
    danger = models.CharField(u'是否危险化学品',max_length = 30)
    production_capacity = models.CharField(u'生产能力（年/吨）',max_length = 30)
    output = models.CharField(u'前三年产量',max_length = 30)

    #原料
    raw_material_name = models.CharField(u'原料名称',max_length = 30)
    raw_material_danger = models.CharField(u'是否危险化学品',max_length = 30)
    raw_material_consumption = models.CharField(u'消耗定额(吨/吨产品)',max_length = 30)
    raw_material_usage = models.CharField(u'设计使用量(吨/年)',max_length = 30)
    raw_material_output = models.CharField(u'前三年产量',max_length = 30)

    #辅料
    accessories_name = models.CharField(u'辅料名称',max_length = 30)
    accessories_danger = models.CharField(u'是否危险化学品',max_length = 30)
    accessories_consumption = models.CharField(u'消耗定额(吨/吨产品)',max_length = 30)
    accessories_usage = models.CharField(u'设计使用量(吨/年)',max_length = 30)
    accessories_output = models.CharField(u'前三年产量',max_length = 30)
    accessories_code = models.CharField(u'用途代码',max_length = 30)

    #工艺情况
    process_name = models.CharField(u'工艺方法名称',max_length = 30)
    equipment_state = models.CharField(u'设备状态',max_length = 30)
    time = models.CharField(u'设备投入使用时间',max_length = 30)
    operation_mode = models.CharField(u'操作方式',max_length =30)
    description = models.CharField(u'工艺流程描述',max_length = 200)
    process_chart  =models.FileField(u'工艺流程图',upload_to= 'static\\upload\\%Y\\%m-%d',null=True,blank=True)

    object = models.CharField(u'对象',max_length = 30)
    object_state = models.CharField(u'状态',max_length = 30)
    elimination_time = models.CharField(u'淘汰时间',max_length = 30)


    #生产线三废去向
    wastewater_whereabouts = models.CharField(u'废水去向',max_length = 30)
    wastewater_quantity = models.CharField(u'废水量(吨/年)',max_length = 30)

    exhaust_whereabouts = models.CharField(u'工艺废气去向',max_length = 30)
    exhaust_quantity = models.CharField(u'工艺废气量(万立方米/年)',max_length = 30)

    waste_material_whereabouts = models.CharField(u'危险废物去向',max_length = 30)
    waste_material_unit = models.CharField(u'利用，处置，贮存设施名称或接受单位名称',max_length = 30)
    waste_material_quantity = models.CharField(u'利用，处置，贮存或转移量(吨/年)',max_length = 30)

    #特征化学污染物信息
    chemical_name = models.CharField(u'特征化学污染物名称',max_length = 30)
    ability = models.CharField(u'产污强度(千克/吨产品)',max_length = 30)
    pollution_node = models.CharField(u'产污节点',max_length = 30)
    whereabouts = models.CharField(u'排放去向',max_length = 30)
    enterprise = models.ForeignKey(Enterprise)
